import React, { memo, useCallback } from 'react';
import { Button, message } from 'antd';

import { isSuccess } from '@/utils/request';

import { salaryRecheck } from '@/services/salaryManage/salaryCalculate';

// 申请付款
const ApplyPayment = memo(({ handleItem, year, organizationCode, month, selectedRows, updateStateFn }) => {
    const handleFn = useCallback(async () => {
        if (selectedRows && selectedRows.length > 0) {
            message.warn('申请付款为全量行为，请直接点击按钮');
            return;
        }
        const applyRes = await salaryRecheck.applyPayment({
            year,
            month,
            organizationCode
        })
        if (isSuccess(applyRes)) {
            message.success(applyRes.msg);
            updateStateFn()
        } else {
            message.error(applyRes.msg);
        }
    }, [month, organizationCode, selectedRows, updateStateFn, year]);


    return (
        <Button key={handleItem.code} onClick={handleFn}>
            {handleItem.name}
        </Button>
    );
});

export default memo(ApplyPayment)
